/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.session;

import com.aptech.entity.News;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Tuan Nguyen
 */
@Stateless
public class NewsFacade extends AbstractFacade<News> implements NewsFacadeLocal {
    @PersistenceContext(unitName = "mysweethome.com-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public NewsFacade() {
        super(News.class);
    }
    @Override
    public java.util.List<News> topNews() {
        Query q=em.createNativeQuery("Select Top 7 * FROM News Where IsActive='True' ORDER BY NewsID DESC", News.class);
        return q.getResultList();
    }

    @Override
    public java.util.List<News> SearchNews(String field, String value) {
        Query q=em.createNativeQuery("SELECT * FROM News AS e WHERE "+field+" like ?value", News.class);
        q.setParameter("value", value);
        return q.getResultList();
    }
    
}
